<?php
/***************************************************************
*  Copyright notice
*  (c) 2009, jianyuzhu@gmail.com
*  All rights reserved
*  This script is part of the PPEMI project.
***************************************************************/

//
set_time_limit(0);

//
require(dirname(dirname(__FILE__)) . '/includes/application_top.php');
//
include_once(CONFIG_PATH . CONFIG_DIR_INCLUDES . 'functions/thumb.function.php');
include_once(CONFIG_PATH . CONFIG_DIR_CLASSES . 'core.directory.class.php');

//
define('DIR_PROCESS_FILES', CONFIG_PATH . 'templates/');

//
$templates = array('default', 'default_zh');
$template_base = 'default_zh';

//
function _process_files($dir_compare, $dir_base) {
	$dObj = new CoreDirectoryParser(DIR_PROCESS_FILES . $dir_base);
	$dObj->parse();
	$_dir = $dObj->_dir;
	$files = $dObj->getFiles();
	$dirs = $dObj->getDirs();
	//
	if( is_array($dirs) ) {
		for($i=0, $n=sizeof($dirs); $i<$n; $i++) {
			if( !is_dir(DIR_PROCESS_FILES . $dir_compare . $dirs[$i] . '/') ) {
				mkdir(DIR_PROCESS_FILES . $dir_compare . $dirs[$i] . '/');
			}
			_process_files($dir_compare . $dirs[$i] . '/', $dir_base . $dirs[$i] . '/');
		}
	}
	//
	if( is_array($files) ) {
		for($i=0, $n=sizeof($files); $i<$n; $i++) {
			if( substr($files[$i]['file'], 0, strlen('product_xxx')) == 'product_xxx' ) {
				//
			} elseif( !file_exists(DIR_PROCESS_FILES . $dir_compare . $files[$i]['file']) ) {
				/*
				if( substr($files[$i]['file'], 0, strlen('admin_')) == 'admin_' 
						|| substr($files[$i]['file'], 0, strlen('my_')) == 'my_' 
						|| substr($files[$i]['file'], 0, strlen('member_')) == 'member_' 
						|| substr($files[$i]['file'], 0, strlen('mail_')) == 'mail_' 
						|| substr($files[$i]['file'], 0, strlen('pagelayout_')) == 'pagelayout_' 
					) {
					echo $files[$i]['file'];echo '<br>';
					copy(DIR_PROCESS_FILES . $dir_base . $files[$i]['file'], DIR_PROCESS_FILES . $dir_compare . $files[$i]['file']);
				}*/
				copy(DIR_PROCESS_FILES . $dir_base . $files[$i]['file'], DIR_PROCESS_FILES . $dir_compare . $files[$i]['file']);
			}
		}
	}
	//
}

//
foreach($templates as $k => $template) {
	if( $template != $template_base ) {
		echo $template;echo '/';echo '<br>';
		_process_files($template . '/', $template_base . '/');
		
		//
		//echo $template;echo '/admin/';echo '<br>';
		//_process_files($template . '/admin/', $template_base . '/admin/');
		//echo $template;echo '/pagelayout/';echo '<br>';
		//_process_files($template . '/pagelayout/', $template_base . '/pagelayout/');
	}
}

//
echo 'OK';
//
?>